package com.example.nbb.Service;

import com.example.nbb.Dao.ProductDao;
import com.example.nbb.Dao.UserDao;
import com.example.nbb.Entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class ProductService {
    private static final Logger logger = LoggerFactory.getLogger(ProductService.class);//日志。getLogger需要传入当前的类名

    @Resource
    ProductDao productDao;

    /**
     * 根据商品分类获取商品信息
     *
     * @param sort 分类
     * @return 返回
     */
    public String getAllProduct(String sort) {
        try {
            return ResultEntity.success(productDao.selectProductBySort(sort));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 根据商品id获取商品信息
     * @param productId
     * @return
     */
    public String getAllProduct(int productId) {
        try {
            return ResultEntity.success(productDao.selectProduct(productId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }


}
